/**
 * Copyright 2012 Simple-Jdbc-Lightweight

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package org.mlu.jdbc.simple;

import javax.sql.DataSource;
import snaq.db.DBPoolDataSource;

/**
 *
 * @author Mlungisi Sincuba
 * @since 1.0
 */
public class ConnectionPool {

    private String name = "defaultDS";
    private String driverClassName;
    private String url;
    private String user;
    private String password;
    private int minPool = 5;
    private int maxPool = 10;
    private int maxSize = 30;

    public ConnectionPool(String dataSourceName, String driver, String url, String user, String password) {
        this(driver, url, user, password);
        this.name = dataSourceName;
    }

    public ConnectionPool(String driver, String url, String user, String password) {
        this.driverClassName = driver;
        this.url = url;
        this.user = user;
        this.password = password;
    }

    public ConnectionPool(String dataSourceName, String driver, String url, String user, String password, int minPool, int maxPool, int maxSize) {
        this(dataSourceName, driver, url, user, password);
        this.minPool = minPool;
        this.maxPool = maxPool;
        this.maxSize = maxSize;

    }

    public DataSource getDataSource() {
        DBPoolDataSource ds = new DBPoolDataSource();
        ds.setName(name);
        ds.setDescription("Pooling DataSource");
        ds.setDriverClassName(driverClassName);
        ds.setUrl(url);
        ds.setUser(user);
        ds.setPassword(password);
        ds.setMinPool(minPool);
        ds.setMaxPool(maxPool);
        ds.setMaxSize(maxSize);
        return ds;
    }
   
    
    public DataSource getDataSource(String driver, String url, String user, String password) {
        DBPoolDataSource ds = new DBPoolDataSource();
        ds.setName(name);
        ds.setDescription("Pooling DataSource");
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setUser(user);
        ds.setPassword(password);
        ds.setMinPool(minPool);
        ds.setMaxPool(maxPool);
        ds.setMaxSize(maxSize);
        return ds;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the driverClassName
     */
    public String getDriverClassName() {
        return driverClassName;
    }

    /**
     * @param driverClassName the driverClassName to set
     */
    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    /**
     * @return the url
     */
    public String getUrl() {
        return url;
    }

    /**
     * @param url the url to set
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * @return the user
     */
    public String getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(String user) {
        this.user = user;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the minPool
     */
    public int getMinPool() {
        return minPool;
    }

    /**
     * @param minPool the minPool to set
     */
    public void setMinPool(int minPool) {
        this.minPool = minPool;
    }

    /**
     * @return the maxPool
     */
    public int getMaxPool() {
        return maxPool;
    }

    /**
     * @param maxPool the maxPool to set
     */
    public void setMaxPool(int maxPool) {
        this.maxPool = maxPool;
    }

    /**
     * @return the maxSize
     */
    public int getMaxSize() {
        return maxSize;
    }

    /**
     * @param maxSize the maxSize to set
     */
    public void setMaxSize(int maxSize) {
        this.maxSize = maxSize;
    }
}

